package shupaiwen;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

public class MainFrame extends javax.swing.JFrame{
	private JButton btnOut;
	private JScrollPane scrollPane;
	private JTextArea textArea;
	public MainFrame(){
		initComponents();
		System.setOut(new GUIPrintStream(System.out,textArea));
	}
	private void initComponents(){
		scrollPane = new JScrollPane();
		textArea = new JTextArea();
		btnOut = new JButton();
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setTitle("标准输出重定向到GUI");
		textArea.setColumns(40);
		textArea.setRows(20);
		scrollPane.setViewportView(textArea);
		getContentPane().add(scrollPane,BorderLayout.CENTER);
		btnOut.setText("System.out.println(System.getProperties());");
		btnOut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				btnOutActionPerformed(e);
			}

			private void btnOutActionPerformed(ActionEvent e) {
				System.out.println(System.getProperties());
			}
		});
		getContentPane().add(btnOut,BorderLayout.PAGE_END);
		pack();
		

		
	}
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable(){
			public void run() {
				new MainFrame().setVisible(true);
			}
		});
	}
	
}
